/***************************************************
 @Name :        1196kk0
 @Time :        2025-05-26
 @Email :       2232506563@qq.com
 @Comment :     初始化外部中断
 @FileName :    drv_exti.c
 @Version :     4.0
****************************************************/

#include "drv_exti.h"

/***************************************
函数名：drv_exti9_init
函数功能：初始化USER按键外部中断
输入参数：无
输出参数：无
其它：//USER      PF9
****************************************/
void drv_exti9_init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;
    EXTI_InitTypeDef EXTI_InitStruct;
    NVIC_InitTypeDef NVIC_InitStruct;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF , ENABLE); //开GPIO时钟 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG , ENABLE); //开系统配置时钟

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
    
    GPIO_Init(GPIOF , &GPIO_InitStruct);

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF , EXTI_PinSource9); //配置引脚为EXTI

    EXTI_InitStruct.EXTI_Line = EXTI_Line9;                 //外部中断线9
    EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;        //中断模式
    EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;    //下降沿触发
    EXTI_InitStruct.EXTI_LineCmd = ENABLE;                  //外部中断使能
    EXTI_Init(&EXTI_InitStruct);

    NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;         //中断通道号
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;  //抢占优先级
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;         //响应优先级
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;            //NVIC使能
    NVIC_Init(&NVIC_InitStruct);
}




